package com.atguigu.gulimall.gulimallgateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * @Author yanhao
 * @Date 2021/2/2 10:13
 * Designed www.sinog2c.com
 **/
@Configuration
public class GulimallCorsConfiguration {


    @Bean
    public CorsWebFilter corsWebFilter(){    /* 配置跨越*/
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        /**允许哪些头*/
        corsConfiguration.addAllowedHeader("*");
        /** 允许哪些请求方式*/
        corsConfiguration.addAllowedMethod("*");
        /**  允许请求来源*/
        corsConfiguration.addAllowedOrigin("*");
         /**是否允许携带cookie跨越*/
        corsConfiguration.setAllowCredentials(true);
         /**注册跨越配置*/
        source.registerCorsConfiguration("/**",corsConfiguration);
        return new CorsWebFilter(source);
    }
}
